package tmproject.hlhj.fhp.cartrans.adapter

import android.content.Intent
import android.os.Bundle
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import tmproject.hlhj.fhp.cartrans.R
import tmproject.hlhj.fhp.cartrans.activitys.ClassDetailAty
import tmproject.hlhj.fhp.cartrans.customVIews.ConfirmDialog
import tmproject.hlhj.fhp.cartrans.http.NumUtil
import tmproject.hlhj.fhp.cartrans.javaBean.ClassListBean

/**
 * Created by Administrator on 2018/8/28/028.
 */
class LearnListAdp(private val datas:ArrayList<ClassListBean.DataBean.ListBean>)
    :BaseQuickAdapter<ClassListBean.DataBean.ListBean,BaseViewHolder>(R.layout.fgm_learn_list_item,datas) {
    var lisener:JumpListener?=null
    override fun convert(helper: BaseViewHolder?, item: ClassListBean.DataBean.ListBean?) {
        helper?.let {
            it.setText(R.id.itemTittle,item?.title)
            if (item?.progress==-1.00f){
                it.setText(R.id.itemPro,"【未开始】共${item?.required_time}分钟")
                val bt = it.getView<TextView>(R.id.btGoLearn)
                it?.setText(R.id.btGoLearn,"去学习")
                bt.setOnClickListener {
                    val intent = Intent(mContext, ClassDetailAty::class.java)
                    intent.putExtra("id",datas[helper?.adapterPosition].id)
                    lisener?.jump(intent)
                }
            }else{
                if (item?.progress!=1.00f){
                    it?.setText(R.id.btGoLearn,"去学习")
                    it.setText(R.id.itemPro,"【已开始】还需学习${NumUtil.formatNum((item?.required_time!!-item?.learned_time),2)}分钟")
                    val bt = it.getView<TextView>(R.id.btGoLearn)
                    bt.setOnClickListener {
                        try {
                            val intent = Intent(mContext, ClassDetailAty::class.java)
                            intent.putExtra("id",datas[helper?.adapterPosition].id)
                            lisener?.jump(intent)
                        }catch (e:Exception){

                        }

                    }
                }else{
                    it.setText(R.id.itemPro,"【已完成】")
                    if (item?.sign_pic==null||item?.driver_pic==null){
                        it?.setText(R.id.btGoLearn,"提交认证")
                        val bt = it.getView<TextView>(R.id.btGoLearn)
                        bt.setOnClickListener {
                            val bundle = Bundle()
                            bundle.putInt("id",item?.id)
                            bundle.putString("learned_time",item?.required_time.toString())
                            val confirmDialog = ConfirmDialog(mContext, 2, bundle)
                            confirmDialog.show()
                        }
                    }else{
                        it?.setText(R.id.btGoLearn,"已提交认证")
                        val bt = it.getView<TextView>(R.id.btGoLearn)
                        bt.setOnClickListener {

                        }
                    }


                }
            }
        }
    }

    interface JumpListener{
        fun jump(intent:Intent)
    }
}